package com.ruoyi.cat.service.impl;

import java.util.Collections;
import java.util.List;

import com.ruoyi.cat.domain.AdTicketImage;
import com.ruoyi.cat.domain.AdTicketOrder;
import com.ruoyi.cat.domain.DTO.TicketOrderDTO;
import com.ruoyi.cat.domain.VO.TicketOrderVO;
import com.ruoyi.cat.mapper.AdTicketOrderMapper;
import com.ruoyi.cat.service.IAdTicketImageService;
import com.ruoyi.cat.service.IAdTicketOrderService;
import com.ruoyi.common.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * 折扣订单Service业务层处理
 * 
 * @author ruoyi
 * @date 2025-07-16
 */
@Service
public class AdTicketOrderServiceImpl implements IAdTicketOrderService
{
    @Autowired
    private AdTicketOrderMapper adTicketOrderMapper;

    @Autowired
    private IAdTicketImageService adTicketImageService;

    /**
     * 查询折扣订单
     * 
     * @param id 折扣订单主键
     * @return 折扣订单
     */
    @Override
    public AdTicketOrder selectAdTicketOrderById(Long id)
    {
        return adTicketOrderMapper.selectAdTicketOrderById(id);
    }

    /**
     * 查询折扣订单列表
     * 
     * @param adTicketOrder 折扣订单
     * @return 折扣订单
     */
    @Override
    public List<AdTicketOrder> selectAdTicketOrderList(AdTicketOrder adTicketOrder)
    {
        return adTicketOrderMapper.selectAdTicketOrderList(adTicketOrder);
    }

    /**
     * 新增折扣订单
     * 
     * @param adTicketOrder 折扣订单
     * @return 结果
     */
    @Override
    public int insertAdTicketOrder(AdTicketOrder adTicketOrder)
    {
        adTicketOrder.setCreateTime(DateUtils.getNowDate());
        return adTicketOrderMapper.insertAdTicketOrder(adTicketOrder);
    }

    /**
     * 修改折扣订单
     * 
     * @param adTicketOrder 折扣订单
     * @return 结果
     */
    @Override
    public int updateAdTicketOrder(AdTicketOrder adTicketOrder)
    {
        return adTicketOrderMapper.updateAdTicketOrder(adTicketOrder);
    }

    @Override
    public int updateAdTicketOrderByOrderCode(AdTicketOrder adTicketOrder) {
        return adTicketOrderMapper.updateAdTicketOrderByOrderCode(adTicketOrder);
    }

    @Override
    public AdTicketOrder selectAdTicketByOrderCode(String orderCode) {
        return adTicketOrderMapper.selectAdTicketByOrderCode(orderCode);
    }

    @Override
    public AdTicketOrder selectAdTicketByRefundOrder(String refundOrder) {
        return adTicketOrderMapper.selectAdTicketByRefundOrder(refundOrder);
    }

    /**
     * 批量删除折扣订单
     * 
     * @param ids 需要删除的折扣订单主键
     * @return 结果
     */
    @Override
    public int deleteAdTicketOrderByIds(Long[] ids)
    {
        return adTicketOrderMapper.deleteAdTicketOrderByIds(ids);
    }

    /**
     * 删除折扣订单信息
     * 
     * @param id 折扣订单主键
     * @return 结果
     */
    @Override
    public int deleteAdTicketOrderById(Long id)
    {
        return adTicketOrderMapper.deleteAdTicketOrderById(id);
    }

    @Override
    public List<TicketOrderDTO> selectAdTicketOrderByOrderCode(TicketOrderVO ticketOrderVO) {
       List<TicketOrderDTO> list =  adTicketOrderMapper.selectAdTicketOrderByOrderCode(ticketOrderVO);
        list.forEach(iAdTicketRoll->{
            AdTicketImage adTicketImage = new AdTicketImage();
            adTicketImage.setTicketId(iAdTicketRoll.getTicketId());
            List<AdTicketImage> adTicketImageList = adTicketImageService.selectAdTicketImageList(adTicketImage);
            iAdTicketRoll.setTicketImageList(adTicketImageList);
        });
        return list;
    }
}
